package com.terracloud.server.service.log;

import com.terracloud.server.common.data.id.DeviceId;
import com.terracloud.server.common.data.id.TenantId;
import com.terracloud.server.common.data.id.UserId;
import com.terracloud.server.common.data.log.LogLevel;
import com.terracloud.server.common.data.log.LogType;
import com.terracloud.server.common.data.log.LogStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * UnifiedLogUtil使用示例服务
 * 提供测试UnifiedLogUtil功能的方法
 */
@Service
@Slf4j
public class UnifiedLogUtilExampleService {
    
    /**
     * 执行UnifiedLogUtil完整功能示例
     * 演示UnifiedLogUtil工具类的所有功能
     */
    public void executeCompleteExample() {
        // 使用当前登录租户ID
        DeviceId deviceId = new DeviceId(UUID.randomUUID());
        
        log.info("=== UnifiedLogUtil完整功能示例开始 ===");

        // 涵盖所有日志类型的记录方法
        demonstrateAllLogTypes(deviceId);
        
        log.info("=== UnifiedLogUtil完整功能示例结束 ===");
    }

    /**
     * 演示涵盖所有日志类型的记录方法
     */
    private void demonstrateAllLogTypes(DeviceId deviceId) {
        log.info("涵盖所有日志类型的记录方法:");
        
        // 终端日志类型演示
        log.info("   终端日志类型:");
        
        UnifiedLogUtil.logTerminal(
                deviceId,
                "Device-Name",
                LogType.ALERT_LOG,
                LogLevel.WARNING,
                "设备告警日志",
                "设备告警日志详情",
                "processor",
                LogStatus.UNPROCESSED,
                "NORMAL",
                System.currentTimeMillis() + 3600000,
                120000L,
                true
        );
        
        UnifiedLogUtil.logTerminal(
                deviceId,
                "Device-Name",
                LogType.PROCESS_LOG,
                LogLevel.INFO,
                "设备处理日志",
                "设备处理日志详情",
                "processor",
                LogStatus.UNPROCESSED,
                "NORMAL",
                System.currentTimeMillis() + 3600000,
                120000L,
                false
        );
        
        UnifiedLogUtil.logTerminal(
                deviceId,
                "Device-Name",
                LogType.RECEIVE_LOG,
                LogLevel.INFO,
                "设备接收日志",
                "设备接收日志详情",
                "processor",
                LogStatus.UNPROCESSED,
                "NORMAL",
                System.currentTimeMillis() + 3600000,
                120000L,
                false
        );
        
        UnifiedLogUtil.logTerminal(
                deviceId,
                "Device-Name",
                LogType.RECEIVE_EXCEPTION_LOG,
                LogLevel.CRITICAL,
                "设备接收异常日志",
                "设备接收异常日志详情",
                "processor",
                LogStatus.UNPROCESSED,
                "NORMAL",
                System.currentTimeMillis() + 3600000,
                120000L,
                true
        );
        
        // 平台日志类型演示
        log.info("   平台日志类型:");
        
        UnifiedLogUtil.logPlatform(
                LogType.EXCEPTION_LOG,
                LogLevel.CRITICAL,
                "系统异常日志",
                "系统异常日志详情",
                "BIZ-001",
                "{}",
                "ACTIVE -> PROCESSED",
                "No exception",
                "192.168.1.100",
                "SUCCESS"
        );
        
        UnifiedLogUtil.logPlatform(
                LogType.BUSINESS_LOG,
                LogLevel.INFO,
                "业务操作日志",
                "业务操作日志详情",
                "BIZ-002",
                "{}",
                "ACTIVE -> PROCESSED",
                null,
                null, // IP地址设为null，让工具类自动获取
                "SUCCESS"
        );
        
        UnifiedLogUtil.logPlatform(
                LogType.AUDIT_LOG,
                LogLevel.INFO,
                "审计日志",
                "审计日志详情",
                "BIZ-003",
                "{}",
                "ACTIVE -> PROCESSED",
                null,
                null, // IP地址设为null，让工具类自动获取
                "SUCCESS"
        );
        
        UnifiedLogUtil.logPlatform(
                LogType.OPERATION_LOG,
                LogLevel.INFO,
                "用户操作日志",
                "用户操作日志详情",
                "BIZ-004",
                "{}",
                "ACTIVE -> PROCESSED",
                null,
                null, // IP地址设为null，让工具类自动获取
                "SUCCESS"
        );
        
        log.info("   所有日志类型记录方法演示完成");
    }
}